<?php
#
#
# Copyright TEDECO, 2009. http://tedeco.fi.upm.es
#
# This file is part of kumenya.
#
# Kumenya is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Kumenya is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
#
#
#
?>
<?php
	include("../commons/classes.php");
	include("../commons/www.php");

	include(Action . "CamposDeApunte.php");
	include(Action . "TransactionDetails.php");
	
	Interfaz::Header(_("Transaction") . " " . _("Modification"), TRUE);
	
	Interfaz::NextScreen ();
		
	Interfaz::Control($entryFields);

	Interfaz::OpenBody(FALSE);	

	if ($result) {
		Interfaz::Buttons ();

		if ($showData != 2) {
			// BACK
			Interfaz::NavigationButton(_("Back"), $origin, "back");
			
			// REFRESH TRANSACTION
			Interfaz::NavigationButton (_("New") . " " . _("Entry"), Page. "TransactionDetails.php", "form", TRUE);
	
			// MODIFY TRANSACTION
			Interfaz::NavigationButton (_("Transaction") . " " . _("Modification"), Page. "TransactionModification.php", "form");

			// DELETE TRANSACTION
			Interfaz::NavigationButton(_("Remove") . " " . _("Transaction"), Page. "CancelTransaction.php", "form");
		}
		else if ($showData == 2) {
			// BACK
			Interfaz::NavigationButton(_("Back"), Page. "TransactionDetails.php", "back");
			
			// REFRESH ENTRY
			Interfaz::NavigationButton (_("Entry") . " " . _("Modification"), Page. "TransactionDetails.php", "form", TRUE);
			
			// DELETE ENTRY
			Interfaz::NavigationButton (_("Remove") . " " . _("Entry"), Page. "TransactionDetails.php", "remove", TRUE);
		}

		// SEARCH ACCOUNTS
		Interfaz::CallingAction("Select");
		$accountingAccountFields = Interfaz::FieldsType($accountingAccountFields, Type);
		Interfaz::SearchButton (_("Search") . " " . _("Accounting accounts"), Page."AccountingAccountSearchCriterias.php", AccountingAccountFields, $accountingAccountFields);

		Interfaz::CloseButtons ();

		if ($showMessage && result) {
			echo _("THERE IS NO ERROR") . ": " . _($message);
			Interfaz::WhiteLine(2);
		}

		Interfaz::SearchResults($table,"Entry", FALSE, TRUE);
		
		Interfaz::SearchResults($total,"Total");
		
		Interfaz::WhiteLine(2);

		// NEW ENTRIES
		Interfaz::Form (Page. "TransactionDetails.php");
		if ($showData == 0)
			Interfaz::Fields($entryFields, Interfaz::Data(), $notEditables);
		else if ($showData == 1)
			Interfaz::Fields($entryFields, $transactionData, $notEditables);
		else if ($showData == 2) {		
			Interfaz::Fields($entryFields, $data, $notEditables);
		}
						
		if ($showData == 2)
			Interfaz::ObjectType ("Modify");
		else
			Interfaz::ObjectType (Entry);
			
		Interfaz::CloseForm();
		
		// FORM FOR REMOVING AN ENTRY
		if ($showData == 2) {
			Interfaz::Form (Page. "TransactionDetails.php", "remove");
			Interfaz::Send($data);
			Interfaz::ObjectType ("Cancel");
			Interfaz::CloseForm ();
		}


		if ($showData == 2) {
			// FORM FOR GOING BACK
			Interfaz::Form (Page. "TransactionDetails.php", "back");
			Interfaz::Send($transactionData);
			Interfaz::CloseForm ();
		}
		else {
			// FORM FOR GOING BACK
			Interfaz::Form (Page. "TransactionDetails.php", "back");			
			Interfaz::Send($goBackData);
			Interfaz::CloseForm ();
		}

	}
	else {
		Interfaz::Buttons ();	
		// BACK
		Interfaz::NavigationButton(_("Try again"), Page. "TransactionDetails.php", "back");
		Interfaz::CloseButtons ();
	
		$error = Interfaz::Error();	
		echo _("THERE IS AN ERROR") . ": " . _($error);

		// FORM FOR GOING BACK
		Interfaz::Form (Page. "TransactionDetails.php", "back");
		Interfaz::Send(Interfaz::Data());

		if ($action == "Modify")	
			Interfaz::ObjectType ("Entry");
			
		Interfaz::CloseForm ();
	}

	Interfaz::End();

?>